package com.notary.tx_live_plugin.platform;

import androidx.annotation.NonNull;

import com.notary.tx_live_plugin.util.ChatManager;
import com.notary.tx_live_plugin.util.TxConstant;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

/**
 * 推流，接收flutter消息处理MethodCallHandler
 */
public class ChatMethodCallHandlerImpl implements MethodChannel.MethodCallHandler {

    private final ChatManager chatManager;
    public ChatMethodCallHandlerImpl(ChatManager chatManager){
        this.chatManager = chatManager;
    }

    @Override
    public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
        switch (call.method){
            case TxConstant.ChatMethod.startChat: //开启视频聊天
                result.success(chatManager.startChat(call.arguments));
                return;
            case TxConstant.ChatMethod.stopChat: //结束视频聊天 退出房间
                chatManager.stopChat();
                break;
            case TxConstant.ChatMethod.onPause:
                chatManager.onPause();//方法暂时不做处理
                break;
            case TxConstant.ChatMethod.onResume:
                chatManager.onResume();//方法暂时不做处理
                break;
            case TxConstant.ChatMethod.onDestroy:
                chatManager.onDestroy();
                break;
            case TxConstant.ChatMethod.isCreating: //是否是房间创建者
                result.success(chatManager.isCreating());
                return;
            case TxConstant.ChatMethod.isOpenAudio: //当前用户是否开启音频
                result.success(chatManager.isOpenAudio());
                return;
            case TxConstant.ChatMethod.switchAudio: //切换 音频的开启
                result.success(chatManager.switchAudio());
                return;
            default:
                result.notImplemented();
                return;
        }
        result.success(true);
    }
}
